'use strict';
module.exports = {
	/**
	 * 用于快手或抖音小程序首页获取用户信息，不能删除
	 */
	main: async (event) => {
		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {
			customUtil,
			uniID,
			config,
			pubFun,
			vk,
			db,
			_
		} = util;
		let {
			uid,
			openid
		} = data;
		let res = {
			code: 0,
			msg: ""
		};
		// 业务逻辑开始-----------------------------------------------------------
		//检查该openid是否在数据里里已有数据
		res.user = await db.collection('uni-id-users').where({
			ks_openid: openid
		}).get()
		
		//如果存在用户，就token数量值，超过10个就清空，避免个人数据太大
		if (res.user.data.length > 0) {
			let tokennum = res.user.data[0].token.length
			if (tokennum > 10) {
				let deltoken = await db.collection('uni-id-users').where({
					ks_openid: openid
				}).update({
					token: []
				})
			}
		}
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
